package com.naiterui.ehp.bp.bo.payment;

import org.apache.commons.lang3.StringUtils;

import lombok.Data;

/**
 * 通知业务数据
 *
 * @author 王泽浩
 * @since 1.0.0
 */
@Data
public class NotifyBusinessRequestBO implements java.io.Serializable {

    /**
     * 通知类型：支付回调
     */
    public static final int NOTIFY_TYPE_PAY = 1;
    /**
     * 通知类型：退款回调
     */
    public static final int NOTIFY_TYPE_REFUND = 2;

    /**
     * 业务通知成功
     */
    public static final int NOTIFY_STATUS_SUCCESS = 1;

    /**
     * 业务通知失败
     */
    public static final int NOTIFY_STATUS_FAILURE = 2;

    private static final long serialVersionUID = -6222824932746626153L;

    /**
     * 业务订单号
     */
    private String orderSn;

    /**
     * 退款单号
     */
    private String refundOrderSn;
    /**
     * 通知类型
     */
    private Integer notifyBusinessType;
    /**
     * 通知业务地址
     */
    private String notifyBusinessUrl;
    /**
     * post body 请求
     */
    private String body;

    private int recoverTime;

    public NotifyBusinessRequestBO(String orderSn, String refundOrderSn, Integer notifyBusinessType, String notifyBusinessUrl, String body) {
        if (notifyBusinessType == null) {
            throw new IllegalArgumentException("通知类型不能为null");
        }
        if (StringUtils.isBlank(notifyBusinessUrl)) {
            throw new IllegalArgumentException("回调地址不能为null");
        }
        this.orderSn = orderSn;
        this.refundOrderSn = refundOrderSn;
        this.notifyBusinessType = notifyBusinessType;
        this.notifyBusinessUrl = notifyBusinessUrl;
        this.body = body;
        this.recoverTime = 0;
    }

    @Override
    public String toString() {
        String notifyBusinessTypeMsg = this.notifyBusinessType == NOTIFY_TYPE_PAY ? "支付回调" : "退款回调";
        return String.format("\n【请求地址】：\n%s\n【请求数据】：\n%s\n【通知类型】：\n%s\n【重试次数】：\n%d", this.notifyBusinessUrl, this.body, notifyBusinessTypeMsg,
                             this.recoverTime);

    }
}
